<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <table class="layui-hide" id="table-page" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableFilter">
            <{if AdminUsersModel::check_right("$module/$controller/save")}>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <{/if}> 
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <{if AdminUsersModel::check_right("$module/$controller/save")}>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加</button>
                <{/if}>
            </div>
        </script>

        <script type="text/html" id="userlist-status-btn">
            {{#  if(d.status == 1){ }}
            <button class="layui-btn layui-btn-xs">正常</button>
            {{#  } else { }}
            <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button>
            {{#  } }}
        </script>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'table', 'miniPage', 'element'], function () {
        var table = layui.table;
        var miniPage = layui.miniPage;
        table.render({
            elem: '#table-page'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter', 'exports']
            , url: '/<{$module}>/<{$controller}>/<{$action}>?do=list&isajax=1'
            , limit: 20
            , height: 'full-150'//一行条件
            , cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true}
                , {field: 'title', title: '标题'}
                , {field: 'account', title: '账户', width: 180}
                // , {field: 'AvailableAmount', title: "可用额度", width: 120}
                , {field: 'accessKeyId', title: "accessKeyId"}
                // , {field: 'AvailableCashAmount', title: "现金余额"}
                , {align: 'left', fixed: 'right', toolbar: '#currentTableFilter'}
            ]]
            , page: true
        });

        var $ = layui.$, active = {
            edit: function (obj) { //获取选中数据
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save/id/' + data.id);
                var index = layer.open({
                    type: 1
                    , title: '编辑'
                    , content: content
                    , area: ['60%', '60%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        layero.find("#form-submit").click();
                    }
                });
            }
            , add: function () {
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save');
                var index = layer.open({
                    title: '添加'
                    , type: 1
                    , shade: 0.5
                    , area: ['60%', '60%']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                });
            }

        };
        //监听工具条
        table.on('tool(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        table.on('toolbar(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
    });
</script>